<html lang="en-US">

<head>
    
<title>「连载十六」在图片上绘制文字 - 花落雨忧</title>

<meta property="og:title" content="「连载十六」在图片上绘制文字 - 花落雨忧">



    



    
    <meta property="description" content="主要实现合并后的海报上绘制文字的功能（这个需求也是常见的很了），内容比较简单。
[&amp;hellip;] 这里使用的是 微软雅黑 的字体，请点击进行下载并存放到 runtime/fonts 目录下（字体文件占 16 MB 大小）
[&amp;hellip;] $ go get -u github.com/golang/freetype &amp;hellip;">
    <meta property="og:description" content="主要实现合并后的海报上绘制文字的功能（这个需求也是常见的很了），内容比较简单。
[&amp;hellip;] 这里使用的是 微软雅黑 的字体，请点击进行下载并存放到 runtime/fonts 目录下（字体文件占 16 MB 大小）
[&amp;hellip;] $ go get -u github.com/golang/freetype &amp;hellip;">
    






<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1">

<link rel="shortcut icon" href="https://www.lican.site/logo/logo.png" type="image/x-icon" />



<link rel="stylesheet" href="/css/style.min.css" />

<link rel="stylesheet" href="/css/reset.min.css" />




<script src="https://www.lican.site/js/highlight.min.js"></script>

<script>
hljs.configure({ ignoreUnescapedHTML: true })
hljs.highlightAll();
</script>


<script src="https://www.lican.site/js/jquery.min.js"></script>




<link href="https://www.lican.site/css/hugo-code.min.css" rel="stylesheet" />



    <style>
        .post-content img {
            max-width: 400px;
        }
    </style>
</head>

<body id="period" class="home blog">
    <a class="skip-content" href="#main">Press "Enter" to skip to content</a>
    <div id="overflow-container" class="overflow-container">
        <header class="site-header" id="site-header" role="banner">
    <div class="max-width">
        <div id="title-container" class="title-container">
            <div id="site-title" class="site-title"><a href="/">花落雨忧</a></div>
            <p class="tagline">思所及 力所行 方为真.</p>
        </div>
        
        <div id="menu-primary-container" class="menu-primary-container">
            <div class="icon-container">
            </div>
            <div id="menu-primary" class="menu-container menu-primary" role="navigation">
                <nav class="menu">
                    <ul id="menu-primary-items" class="menu-primary-items">
                        
                        
                        <li id="menu-item-0"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/posts" aria-current="page" tabindex="0">首页</a></li>
                        
                        <li id="menu-item-1"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/tech/" aria-current="page" tabindex="1">技术文档</a></li>
                        
                        <li id="menu-item-2"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/article/" aria-current="page" tabindex="2">文章</a></li>
                        
                        <li id="menu-item-3"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/project/" aria-current="page" tabindex="3">项目</a></li>
                        
                        <li id="menu-item-4"
                            class="menu-item menu-item-type-custom menu-item-object-custom ">
                            <a href="/about/" aria-current="page" tabindex="4">关于</a></li>
                        
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</header>
        <div id="primary-container" class="primary-container">
            <div class="max-width">
                <section id="main" class="main" role="main">
                    <div id="loop-container" class="loop-container">
                        <div
                            class="post type-post status-publish format-standard hentry entry">
                            <article>
                                <div class="post-container">
                                    <div class="post-header">
                                        <h2 class="post-title">
                                            <a href="/posts/go/gin/2018-07-07-font/">「连载十六」在图片上绘制文字</a>
                                        </h2>
                                        
                                        <div class="post-byline">Published on
                                            <a class="date" href="javascript:;">2018/07/07</a>
                                            
                                            
                                            
                                            By 
                                            <a class="author" href="javascript:;">煎鱼</a></div>
                                            
                                        
                                    </div>
                                    <div class="post-content">
                                        <h2 id="知识点">知识点</h2>
<ul>
<li>字体库使用</li>
<li>图片合成</li>
</ul>
<h2 id="本文目标">本文目标</h2>
<p>主要实现<strong>合并后的海报上绘制文字</strong>的功能（这个需求也是常见的很了），内容比较简单。</p>
<h2 id="实现">实现</h2>
<p>这里使用的是 <a href="https://github.com/EDDYCJY/go-gin-example/blob/master/runtime/fonts/msyhbd.ttc">微软雅黑</a> 的字体，请点击进行下载并<strong>存放到 runtime/fonts 目录</strong>下（字体文件占 16 MB 大小）</p>
<h3 id="安装">安装</h3>
<pre><code>$ go get -u github.com/golang/freetype
</code></pre><h3 id="绘制文字">绘制文字</h3>
<p>打开 service/article_service/article_poster.go 文件，增加绘制文字的业务逻辑，如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">type</span> <span style="color:#a6e22e">DrawText</span> <span style="color:#66d9ef">struct</span> {
	<span style="color:#a6e22e">JPG</span>    <span style="color:#a6e22e">draw</span>.<span style="color:#a6e22e">Image</span>
	<span style="color:#a6e22e">Merged</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">os</span>.<span style="color:#a6e22e">File</span>

	<span style="color:#a6e22e">Title</span> <span style="color:#66d9ef">string</span>
	<span style="color:#a6e22e">X0</span>    <span style="color:#66d9ef">int</span>
	<span style="color:#a6e22e">Y0</span>    <span style="color:#66d9ef">int</span>
	<span style="color:#a6e22e">Size0</span> <span style="color:#66d9ef">float64</span>

	<span style="color:#a6e22e">SubTitle</span> <span style="color:#66d9ef">string</span>
	<span style="color:#a6e22e">X1</span>       <span style="color:#66d9ef">int</span>
	<span style="color:#a6e22e">Y1</span>       <span style="color:#66d9ef">int</span>
	<span style="color:#a6e22e">Size1</span>    <span style="color:#66d9ef">float64</span>
}

<span style="color:#66d9ef">func</span> (<span style="color:#a6e22e">a</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">ArticlePosterBg</span>) <span style="color:#a6e22e">DrawPoster</span>(<span style="color:#a6e22e">d</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">DrawText</span>, <span style="color:#a6e22e">fontName</span> <span style="color:#66d9ef">string</span>) <span style="color:#66d9ef">error</span> {
	<span style="color:#a6e22e">fontSource</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">setting</span>.<span style="color:#a6e22e">AppSetting</span>.<span style="color:#a6e22e">RuntimeRootPath</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">setting</span>.<span style="color:#a6e22e">AppSetting</span>.<span style="color:#a6e22e">FontSavePath</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">fontName</span>
	<span style="color:#a6e22e">fontSourceBytes</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">ioutil</span>.<span style="color:#a6e22e">ReadFile</span>(<span style="color:#a6e22e">fontSource</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">err</span>
	}

	<span style="color:#a6e22e">trueTypeFont</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">freetype</span>.<span style="color:#a6e22e">ParseFont</span>(<span style="color:#a6e22e">fontSourceBytes</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">err</span>
	}

	<span style="color:#a6e22e">fc</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">freetype</span>.<span style="color:#a6e22e">NewContext</span>()
	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetDPI</span>(<span style="color:#ae81ff">72</span>)
	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetFont</span>(<span style="color:#a6e22e">trueTypeFont</span>)
	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetFontSize</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">Size0</span>)
	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetClip</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">JPG</span>.<span style="color:#a6e22e">Bounds</span>())
	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetDst</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">JPG</span>)
	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetSrc</span>(<span style="color:#a6e22e">image</span>.<span style="color:#a6e22e">Black</span>)

	<span style="color:#a6e22e">pt</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">freetype</span>.<span style="color:#a6e22e">Pt</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">X0</span>, <span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">Y0</span>)
	<span style="color:#a6e22e">_</span>, <span style="color:#a6e22e">err</span> = <span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">DrawString</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">Title</span>, <span style="color:#a6e22e">pt</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">err</span>
	}

	<span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">SetFontSize</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">Size1</span>)
	<span style="color:#a6e22e">_</span>, <span style="color:#a6e22e">err</span> = <span style="color:#a6e22e">fc</span>.<span style="color:#a6e22e">DrawString</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">SubTitle</span>, <span style="color:#a6e22e">freetype</span>.<span style="color:#a6e22e">Pt</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">X1</span>, <span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">Y1</span>))
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">err</span>
	}

	<span style="color:#a6e22e">err</span> = <span style="color:#a6e22e">jpeg</span>.<span style="color:#a6e22e">Encode</span>(<span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">Merged</span>, <span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">JPG</span>, <span style="color:#66d9ef">nil</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">err</span>
	}

	<span style="color:#66d9ef">return</span> <span style="color:#66d9ef">nil</span>
}
</code></pre></div><p>这里主要使用了 freetype 包，分别涉及如下细项：</p>
<p>1、freetype.NewContext：创建一个新的 Context，会对其设置一些默认值</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">NewContext</span>() <span style="color:#f92672">*</span><span style="color:#a6e22e">Context</span> {
	<span style="color:#66d9ef">return</span> <span style="color:#f92672">&amp;</span><span style="color:#a6e22e">Context</span>{
		<span style="color:#a6e22e">r</span>:        <span style="color:#a6e22e">raster</span>.<span style="color:#a6e22e">NewRasterizer</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">0</span>),
		<span style="color:#a6e22e">fontSize</span>: <span style="color:#ae81ff">12</span>,
		<span style="color:#a6e22e">dpi</span>:      <span style="color:#ae81ff">72</span>,
		<span style="color:#a6e22e">scale</span>:    <span style="color:#ae81ff">12</span> <span style="color:#f92672">&lt;&lt;</span> <span style="color:#ae81ff">6</span>,
	}
}
</code></pre></div><p>2、fc.SetDPI：设置屏幕每英寸的分辨率</p>
<p>3、fc.SetFont：设置用于绘制文本的字体</p>
<p>4、fc.SetFontSize：以磅为单位设置字体大小</p>
<p>5、fc.SetClip：设置剪裁矩形以进行绘制</p>
<p>6、fc.SetDst：设置目标图像</p>
<p>7、fc.SetSrc：设置绘制操作的源图像，通常为 <a href="https://golang.org/pkg/image/#Uniform">image.Uniform</a></p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">var</span> (
        <span style="color:#75715e">// Black is an opaque black uniform image.
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">Black</span> = <span style="color:#a6e22e">NewUniform</span>(<span style="color:#a6e22e">color</span>.<span style="color:#a6e22e">Black</span>)
        <span style="color:#75715e">// White is an opaque white uniform image.
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">White</span> = <span style="color:#a6e22e">NewUniform</span>(<span style="color:#a6e22e">color</span>.<span style="color:#a6e22e">White</span>)
        <span style="color:#75715e">// Transparent is a fully transparent uniform image.
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">Transparent</span> = <span style="color:#a6e22e">NewUniform</span>(<span style="color:#a6e22e">color</span>.<span style="color:#a6e22e">Transparent</span>)
        <span style="color:#75715e">// Opaque is a fully opaque uniform image.
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">Opaque</span> = <span style="color:#a6e22e">NewUniform</span>(<span style="color:#a6e22e">color</span>.<span style="color:#a6e22e">Opaque</span>)
)
</code></pre></div><p>8、fc.DrawString：根据 Pt 的坐标值绘制给定的文本内容</p>
<h3 id="业务逻辑">业务逻辑</h3>
<p>打开 service/article_service/article_poster.go 方法，在 Generate 方法增加绘制文字的代码逻辑，如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> (<span style="color:#a6e22e">a</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">ArticlePosterBg</span>) <span style="color:#a6e22e">Generate</span>() (<span style="color:#66d9ef">string</span>, <span style="color:#66d9ef">string</span>, <span style="color:#66d9ef">error</span>) {
	<span style="color:#a6e22e">fullPath</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">qrcode</span>.<span style="color:#a6e22e">GetQrCodeFullPath</span>()
	<span style="color:#a6e22e">fileName</span>, <span style="color:#a6e22e">path</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">Qr</span>.<span style="color:#a6e22e">Encode</span>(<span style="color:#a6e22e">fullPath</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span>, <span style="color:#a6e22e">err</span>
	}

	<span style="color:#66d9ef">if</span> !<span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">CheckMergedImage</span>(<span style="color:#a6e22e">path</span>) {
		<span style="color:#f92672">...</span>

		<span style="color:#a6e22e">draw</span>.<span style="color:#a6e22e">Draw</span>(<span style="color:#a6e22e">jpg</span>, <span style="color:#a6e22e">jpg</span>.<span style="color:#a6e22e">Bounds</span>(), <span style="color:#a6e22e">bgImage</span>, <span style="color:#a6e22e">bgImage</span>.<span style="color:#a6e22e">Bounds</span>().<span style="color:#a6e22e">Min</span>, <span style="color:#a6e22e">draw</span>.<span style="color:#a6e22e">Over</span>)
		<span style="color:#a6e22e">draw</span>.<span style="color:#a6e22e">Draw</span>(<span style="color:#a6e22e">jpg</span>, <span style="color:#a6e22e">jpg</span>.<span style="color:#a6e22e">Bounds</span>(), <span style="color:#a6e22e">qrImage</span>, <span style="color:#a6e22e">qrImage</span>.<span style="color:#a6e22e">Bounds</span>().<span style="color:#a6e22e">Min</span>.<span style="color:#a6e22e">Sub</span>(<span style="color:#a6e22e">image</span>.<span style="color:#a6e22e">Pt</span>(<span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">Pt</span>.<span style="color:#a6e22e">X</span>, <span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">Pt</span>.<span style="color:#a6e22e">Y</span>)), <span style="color:#a6e22e">draw</span>.<span style="color:#a6e22e">Over</span>)

		<span style="color:#a6e22e">err</span> = <span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">DrawPoster</span>(<span style="color:#f92672">&amp;</span><span style="color:#a6e22e">DrawText</span>{
			<span style="color:#a6e22e">JPG</span>:    <span style="color:#a6e22e">jpg</span>,
			<span style="color:#a6e22e">Merged</span>: <span style="color:#a6e22e">mergedF</span>,

			<span style="color:#a6e22e">Title</span>: <span style="color:#e6db74">&#34;Golang Gin 系列文章&#34;</span>,
			<span style="color:#a6e22e">X0</span>:    <span style="color:#ae81ff">80</span>,
			<span style="color:#a6e22e">Y0</span>:    <span style="color:#ae81ff">160</span>,
			<span style="color:#a6e22e">Size0</span>: <span style="color:#ae81ff">42</span>,

			<span style="color:#a6e22e">SubTitle</span>: <span style="color:#e6db74">&#34;---煎鱼&#34;</span>,
			<span style="color:#a6e22e">X1</span>:       <span style="color:#ae81ff">320</span>,
			<span style="color:#a6e22e">Y1</span>:       <span style="color:#ae81ff">220</span>,
			<span style="color:#a6e22e">Size1</span>:    <span style="color:#ae81ff">36</span>,
		}, <span style="color:#e6db74">&#34;msyhbd.ttc&#34;</span>)

		<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
			<span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;&#34;</span>, <span style="color:#e6db74">&#34;&#34;</span>, <span style="color:#a6e22e">err</span>
		}
	}

	<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">fileName</span>, <span style="color:#a6e22e">path</span>, <span style="color:#66d9ef">nil</span>
}
</code></pre></div><h2 id="验证">验证</h2>
<p>访问生成文章海报的接口 <code>$HOST/api/v1/articles/poster/generate?token=$token</code>，检查其生成结果，如下图</p>
<p><img src="https://s2.ax1x.com/2020/02/15/1xKBTS.jpg" alt="image"></p>
<h2 id="总结">总结</h2>
<p>在本章节在 <a href="https://github.com/EDDYCJY/blog/blob/master/golang/gin/2018-07-04-Gin%E5%AE%9E%E8%B7%B5-%E8%BF%9E%E8%BD%BD%E5%8D%81%E4%BA%94-%E7%94%9F%E6%88%90%E4%BA%8C%E7%BB%B4%E7%A0%81-%E5%90%88%E5%B9%B6%E6%B5%B7%E6%8A%A5.md">连载十五</a> 的基础上增加了绘制文字，在实现上并不困难，而这两块需求一般会同时出现，大家可以多加练习，了解里面的逻辑和其他 API 😁</p>
<h2 id="参考">参考</h2>
<h3 id="本系列示例代码">本系列示例代码</h3>
<ul>
<li><a href="https://github.com/EDDYCJY/go-gin-example">go-gin-example</a></li>
</ul>
<h2 id="关于">关于</h2>
<h3 id="修改记录">修改记录</h3>
<ul>
<li>第一版：2018 年 02 月 16 日发布文章</li>
<li>第二版：2019 年 10 月 02 日修改文章</li>
</ul>
<h2 id="heading">？</h2>
<p>如果有任何疑问或错误，欢迎在 <a href="https://github.com/EDDYCJY/blog">issues</a> 进行提问或给予修正意见，如果喜欢或对你有所帮助，欢迎 Star，对作者是一种鼓励和推进。</p>
<h3 id="我的公众号">我的公众号</h3>
<p><img src="https://image.eddycjy.com/8d0b0c3a11e74efd5fdfd7910257e70b.jpg" alt="image"></p>


                                        
                                        
                                        
                                        <div class="rp4wp-related-posts">
                                            <h3>相关文章</h3>
                                            <ul>
                                                
                                                <li>
                                                    <div class="rp4wp-related-post-content">
                                                        <a
                                                            href="https://www.lican.site/posts/go/gin/2018-07-05-image/">「连载十五」生成二维码、合并海报</a>
                                                    </div>
                                                </li>
                                                
                                                <li>
                                                    <div class="rp4wp-related-post-content">
                                                        <a
                                                            href="https://www.lican.site/posts/go/gin/2018-06-14-excel/">「连载十四」实现导出、导入 Excel</a>
                                                    </div>
                                                </li>
                                                
                                                <li>
                                                    <div class="rp4wp-related-post-content">
                                                        <a
                                                            href="https://www.lican.site/posts/go/gin/2018-06-02-application-redis/">「连载十三」优化你的应用结构和实现Redis缓存</a>
                                                    </div>
                                                </li>
                                                
                                                <li>
                                                    <div class="rp4wp-related-post-content">
                                                        <a
                                                            href="https://www.lican.site/posts/go/gin/2018-05-27-config-upload/">「连载十二」优化配置结构及实现图片上传</a>
                                                    </div>
                                                </li>
                                                
                                                <li>
                                                    <div class="rp4wp-related-post-content">
                                                        <a
                                                            href="https://www.lican.site/posts/go/gin/2018-04-29-cron/">「连载十一」Cron定时任务</a>
                                                    </div>
                                                </li>
                                                
                                            </ul>
                                        </div>
                                        
                                        
                                    </div>

                                    
                                    
                                    

                                    
                                    <div class="post-meta">
                                        
                                        
                                        <div class="post-tags">
                                            <ul>
                                            
                                            <li>
                                                <a href="/tags/go" title="View all posts tagged match">go</a>
                                            </li>
                                            
                                            <li>
                                                <a href="/tags/gin" title="View all posts tagged match">gin</a>
                                            </li>
                                            
                                            </ul>
                                        </div>
                                        
                                        
                                        <nav class="further-reading">
                                            
                                            <div class="previous">
                                                <span>&lt;&lt; Prev</span>
                                                <a href="https://www.lican.site/posts/go/gin/2018-07-05-image/"
                                                    rel="prev">「连载十五」生成二维码、合并海报</a> </div>
                                            
                                            
                                            <div class="next">
                                                <span>Next >></span>
                                                <a href="https://www.lican.site/posts/go/gin/2018-08-26-makefile/">「番外」请入门 Makefile</a> 
                                            </div>
                                            
                                        </nav>
                                    </div>
                                    
                                    

                                    
                                    
                                    

                                </div>
                            </article>
                        </div>
                    </div>
                </section>
                <aside class="sidebar sidebar-primary" id="sidebar-primary" role="complementary">
    <h1 class="screen-reader-text">Sidebar</h1>
    

    
    
    <section id="text-2" class="widget widget_text">
        <div class="textwidget">
            
            <div id="profile">
                <div id="profile_picture"><img src="https://www.lican.site/logo/logo.png"></div>
                <div id="profile_intro">
                    <p><span class="name">Lican</span></p>
                    <p class="intro">全栈开发者，爱好造轮子。</p>
                </div>
            </div>
            
            <p>
                <script type="text/javascript">
                    (function ($) {
                        $(document).ready(function () {
                            var menuPrimaryContainer = $('#menu-primary-container');
                            var profile = $('#text-2');
                            $('#toggle-navigation').click(function () {
                                if (menuPrimaryContainer.hasClass('open')) {
                                    profile.removeClass('open');
                                } else {
                                    profile.addClass('open');
                                }
                            });
                        });
                    })(jQuery);
                </script>
            </p>
        </div>
    </section>
    
    
    
    
    
    <section id="text-5" class="widget widget_text">
        <h2 class="widget-title">开源项目</h2>
        <div class="textwidget">
            <div id="projects" style="line-height: 22px;">
                
                <a href="https://github.com/idoubi/gonews"
                    target="_blank">gonews</a>: &nbsp;Daily news for golang<br>
                
                <a href="https://github.com/idoubi/sql2struct"
                    target="_blank">sql2struct</a>: &nbsp;Generate go struct according to SQL<br>
                
                <a href="https://github.com/idoubi/goz"
                    target="_blank">goz</a>: &nbsp;Request library used in golang<br>
                
        </div>
    </section>
    
    

    
    
    
    
    

    
    
    

    
    
    

    
    
    
    
</aside>
            </div>
        </div>

        <footer id="site-footer" class="site-footer" role="contentinfo">
    <div class="max-width">
    </div>
    <div class="footer">
        <div id="footercontent">
            © lican.vip All rights reserved<br/>
            Built with Hugo Theme <a href="https://github.com/idoubi/hugo-theme-period" target="_blank">Period</a>
        </div>
    </div>
</footer>

<script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?e8351b6d4626d5881d439ea1f6184baa";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
</script>
    
    
    </div>
    
</body>

</html>